package com.course.redisson.service;

import org.redisson.api.RQueue;
import org.redisson.api.RedissonClient;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.stereotype.Component;

import javax.annotation.Resource;

/**
 * @PROJECT_NAME: course
 * @DESCRIPTION: 队列Queue实战
 * @Author: 涂玄武
 * @DATE: 2021/6/3 10:29
 */
@Component
public class QueuePublisher {

    private static final Logger logger = LoggerFactory.getLogger(QueuePublisher.class);

    @Resource
    private RedissonClient redissonClient;

    /**
     * 发送基本的消息
     * @param msg
     */
    public void sendBasicMsg(String msg){
        try {
            //定义基本队列的名称
            final String queueName = "redissonBasicQueue";
            //获取队列的实例
            RQueue<String> rQueue = redissonClient.getQueue(queueName);
            //往队列中发送消息
            rQueue.add(msg);
            logger.info("队列的生产者-发送基本的消息-消息发送成功：{}",msg);
        } catch (Exception e) {
            logger.error("队列的生产者-发送基本的消息-发生异常：{}",msg,e.fillInStackTrace());
        }
    }

}
